package com.xxg.renrenshoppingcart.dao;

import com.xxg.renrencommon.domain.dao.BaseMapper;
import com.xxg.renrencommon.domain.dao.RenrenShopGoods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface RenrenShopGoodsDao extends BaseMapper<RenrenShopGoods, Integer> {
    @Select("SELECT count(*) FROM renren_shop_goods WHERE id = #{id,jdbcType=INTEGER} AND is_deleted = 0 AND status != 0")
    long countById(Integer id);

    @Select({"<script>",
            "select id,shop_id as shopId,status,title,sub_title as subTitle,short_title as shortTitle,type,thumb,",
            "thumb_all as thumbAll,video,video_thumb as videoThumb,video_type as videoType,stock,sales,",
            "real_sales as realSales,price,min_price as minPrice,max_price as maxPrice,cost_price as costPrice,original_price as originalPrice,",
            "is_deleted as isDeleted,has_option as hasOption,content,is_recommand as isRecommand,is_hot as isHot,",
            "is_new as isNew from renren_shop_goods where id in ",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "AND is_deleted = 0 AND status != 0",
            "</script>"}
            )
    long countByIds(@Param("ids") List<Integer> ids);

    @Select({"<script>",
            "select id,shop_id as shopId,status,title,sub_title as subTitle,short_title as shortTitle,type,thumb,",
            "thumb_all as thumbAll,video,video_thumb as videoThumb,video_type as videoType,stock,sales,",
            "real_sales as realSales,price,min_price as minPrice,max_price as maxPrice,cost_price as costPrice,original_price as originalPrice,",
            "is_deleted as isDeleted,has_option as hasOption,content,is_recommand as isRecommand,is_hot as isHot,",
            "is_new as isNew from renren_shop_goods where id in ",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"})
    List<RenrenShopGoods> selectByIds(@Param("ids") List<Integer> ids);

    @Select("SELECT shop_id FROM renren_shop_goods WHERE id = #{id,jdbcType=INTEGER} AND is_deleted = 0 AND status != 0")
    Integer selectShopIdById(Integer id);
}